<template>
  <el-container>
    <el-aside style="float:left;width: 300px;">
      <el-card class="box-card el-card-flex">
        <div slot="header" class="clearfix">
          <div v-if="selectTreeBox==true">
            <el-select @change="changSelectTree" v-model="selectTreeId" placeholder="请选择">
              <el-option v-for="item in rootTreeData" :key="item.treeId" :label="item.orgName" :value="item.treeId">
              </el-option>
            </el-select>
            <i title="新增" @click='addTree' class="el-icon-plus el-icon--right plus-icon"></i>
            <i title="搜索" @click='treeSearch' class="el-icon-search el-icon--right plus-icon"></i>
          </div>
          <el-input v-else ref='searchFcus' v-model="orgNameSearch" @blur='searchBlur' placeholder="请搜索..." suffix-icon="el-icon-search"></el-input>
        </div>
        <div class="text item el-over-auto">
          <div v-if="initTree">
            <el-tree ref='tree' v-if="!orgNameSearch" :load="loadNode" node-key="id" :props="defaultProps"
              :highlight-current="true" lazy @node-click="handleNodeClick" :current-node-key="currentNodekey"
              :default-expanded-keys="expandedkeys" :key='treeKey'>
            </el-tree>
            <el-tree ref='tree' v-if="orgNameSearch" :data="searchTreeData" node-key="id" :props="defaultProps"
              :highlight-current="true" @node-click="handleNodeClick" default-expand-all>
            </el-tree>
          </div>
        </div>
      </el-card>
    </el-aside>
    <el-main style="padding:0 0 0 10px;">
      <el-card class="box-card el-card-flex">
        <div slot="header" class="clearfix">
          <span>
            <i class="el-icon-warning-outline"></i>
            组织信息
          </span>
          <el-button v-if="editButtonShow==true" plain type="primary" style="float: right;margin-left:10px;" class="el-button-pad"
            @click="editTreeOrg">
            编辑
            <i class="el-icon-edit el-icon--right"></i>
          </el-button>
          <el-button plain type="primary" style="float: right;" class="el-button-pad" @click="addTreeOrg">
            新增
            <i class="el-icon-plus el-icon--right"></i>
          </el-button>
        </div>
        <div class="text item el-over-auto" style="padding:10px 50px">
          <el-form :model='formData' :inline="true" ref='formData' label-width="135px">
            <el-row class='code-first-row'>
              <span class='basic-info'>
                <div class='line-style'></div>组织基本信息
              </span>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="组织名称:">
                  {{formData.name}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="隶属机构:">
                  {{formData.orgName}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="组织分类:">
                  <span v-for="(item,index) in orgTypeData" :key='index'>{{formData.orgType==item.id?item.name:''}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="组织等级:">
                  <span v-for="(item,index) in orgTypeDegree" :key='index'>{{formData.orgDegree==item.id?item.name:''}}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="排序号:">
                  {{formData.sortNo}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="ERP单位编码:">
                  {{formData.erpOrgCode}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="ERP单位名称:">
                  {{formData.erpOrgName}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="备注:">
                  {{formData.remark}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="组织档案编码:">
                  <span style='word-break: break-all'>{{formData.orgCode}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="组织注册ID:">
                  {{formData.id}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="简称:">
                  {{formData.alias}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="曾用名:">
                  {{formData.historyNames}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="英文名:">
                  {{formData.property3}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider class='divider-code'></el-divider>
            <el-row class='code-first-row'>
              <span class='basic-info'>
                <div class='line-style'></div>组织注册信息
              </span>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="社会统一信用代码:">
                  {{formData.creditCode}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="组织机构代码:">
                  {{formData.orgNumber}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="纳税人识别号:">
                  {{formData.taxNumber}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="企业状态:">
                  <span v-for="(item,index) in companyStatus" :key='index'>{{formData.regStatus==item.id?item.name:''}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="注册号:">
                  {{formData.regNumber}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="注册资本:">
                  {{formData.regCapital}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="注册资本币种:">
                  {{formData.regcapitalCurrency}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="公司类型:">
                  <span v-for="(item,index) in companyType" :key='index'>{{formData.companyOrgType==item.id?item.name:''}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="实收注册资金:">
                  {{formData.actualCapital}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="实收注册资本币种:">
                  {{formData.actualCapitalCurrency}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="登记机关:">
                  {{formData.regInstitute}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="国别或地区:">
                  <span v-for="(item,index) in zoneData" :key='index'>{{formData.zone==item.id?item.name:''}}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="省份简称:">
                  {{formData.base}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="注册地址:">
                  {{formData.regLocation}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider class='divider-code'></el-divider>
            <el-row class='code-first-row'>
              <span class='basic-info'>
                <div class='line-style'></div>组织简介
              </span>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="企业标签:">
                  {{formData.tags}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="企业评分:">
                  {{formData.percentileScore}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="小微企业:">
                  <span v-if='formData.isMicroEnt'>{{formData.isMicroEnt=='0'?'是':'否'}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="法人类型:">
                  <span v-if='formData.type'>{{formData.type=='1'?'自然人':'公司'}}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="法人:">
                  {{formData.legalPersonName}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="法人身份证:">
                  {{formData.legalPersonId}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="人员规模:">
                  {{formData.staffNumRange}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="参保人数:">
                  {{formData.socialStaffNum}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="行业:">
                  {{formData.industry}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="股票类型:">
                  <span v-for="(item,index) in bondTypeDatas" :key='index'>{{formData.bondType==item.id?item.name:''}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="股票号:">
                  {{formData.bondNum}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="股票名:">
                  {{formData.bondName}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="股票曾用名:">
                  {{formData.usedBondName}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="成立日期:">
                  {{formData.estiblishTime}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="核准时间:">
                  {{formData.approvedTime}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="经营开始时间:">
                  {{formData.fromTime}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="经营结束时间:">
                  {{formData.toTime}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="吊销日期:">
                  {{formData.revokeDate}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="吊销原因:">
                  {{formData.revokeReason}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="注销日期:">
                  {{formData.cancelDate}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="注销原因:">
                  {{formData.cancelReason}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="登记注册类型:">
                  <span v-for="(item,index) in subOrgReqCatData" :key='index'>{{formData.orgCat==item.id?item.name:''}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="业务板块:">
                  <span v-for="(item,index) in subOrgPlateData" :key='index'>{{formData.bizCat==item.id?item.name:''}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="网站网址:">
                  {{formData.webUrl}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col>
                <el-form-item label="经营范围:">
                  {{formData.businessScope}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-divider class='divider-code'></el-divider>
            <el-row class='code-first-row'>
              <span class='basic-info'>
                <div class='line-style'></div>联系方式
              </span>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="邮编:">
                  {{formData.zipCode}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="电子邮箱:">
                  {{formData.email}}
                </el-form-item>
              </el-col>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="联系人:">
                  {{formData.linkMan}}
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class='code-first-row'>
              <el-col :span="8" class='textarea-inner-style'>
                <el-form-item class='inner-inputs-style' label="联系电话:">
                  {{formData.lintel}}
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-card>
      <!-- 新增组织树 -->
      <el-dialog title="新增组织树" :visible.sync="addDialogTree" :close-on-click-modal="false" :close-on-press-escape="false">
        <el-form :model="treeForm" ref="treeForm" label-width="100px">
          <el-form-item label="组织树名称" prop='orgName' :rules="{ required: true, message: '组织树名称不能为空'}">
            <el-col :span="12">
              <el-input autocomplete="off" v-model="treeForm.orgName"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="组织树编码" prop='orgCode' :rules="{ required: true, message: '组织树编码不能为空'}">
            <el-col :span="12">
              <el-input autocomplete="off" v-model="treeForm.orgCode"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="内置组织树">
            <el-col :span="12">
              <el-switch v-model="treeForm.systemDef" active-value="Y" inactive-value="N"></el-switch>
            </el-col>
          </el-form-item>
          <el-form-item label="描述">
            <el-col :span="12">
              <el-input v-model="treeForm.remark" autocomplete="off" type="textarea" :rows="3"></el-input>
            </el-col>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="treeSave('treeForm')">保存 <i class="el-icon-document-checked el-icon--right"></i></el-button>
          <el-button type="danger" @click="addDialogTree = false">关闭 <i class="el-icon-close"></i></el-button>
        </div>
      </el-dialog>
    </el-main>
  </el-container>
</template>
<script>
  import {
    Tree,
    Dialog,
    MessageBox,
    Message,
    Divider
  } from 'element-ui';
  import {
    archiveDetails, //企业详情
    treeRoot, //组织树根节点
    childrenTree, //父级组织下的下级组织
    addTree, //新增组织树根节点
    deleteTree, //删除组织树中的组织信息
    searchTree, //组织树查询
  }
  from '@/api/org/organizationTree/organizationTree.js'
  import {
    comboBoxDataSelect, //下拉通用接口
  } from '@/api/org/orgnizationArchives/orgnizationArchives.js'
  export default {
    components: {
      'el-tree': Tree, //树形菜单
      'el-dialog': Dialog, //弹窗
      'el-divider': Divider, //分割线
    },
    watch: {
      orgNameSearch(val) { //搜索
        let data = {
          name: val,
          userId: this.currentUserId,
          treeId: this.selectTreeId
        }
        if (val) {
          searchTree(data).then(res => {
            let datas = res.data.data;
            this.removeTip() //移除默认提示
            this.deepChild(datas);
            this.searchTreeData = datas;
          });
        } else {
          this.treeKey += 1;
        }
      }
    },
    created() {
      this.getRootTree()
      this.currentUserId = this.$store.state.userInfo.userId
      this.getsubOrgCat()
      this.getCompanyStatus()
      this.getCompanyType()
      this.getZone()
      this.getBondType()
      this.getBondType()
      this.getSubOrgCat()
      this.getSubOrgPlate()
      this.getsubOrgDegree()
    },
    data() {
      return {
        node: [],
        resolve: [],
        selectTreeBox: true, //下拉树
        selectTreeId: '', //下拉树Id
        selectTreeOrg: '', //下拉树组织
        selectTreeItem: {}, //下拉选中树节点
        rootTreeData: [], //树根节点数据
        orgTypeData: [], //组织类型
        companyStatus: [], //企业状态
        companyType: [], //公司类型
        zoneData: [], //国别或地区
        bondTypeDatas: [], //股票类型
        subOrgReqCatData: [], //登记注册类型
        subOrgPlateData: [], //业务板块
        orgTypeDegree: [], //组织等级
        currentOrgName: '', //当前隶属组织
        currentParentTreeId: '', //当前隶属组织Id
        currentUserId: "", //当前用户Userid
        formData: {}, //展示表单
        addDialogTree: false, //组织树新增
        currentSortNo: '', //当前排序号
        currentErpOrgCode: '', //当前ERP单位编码
        currentErpOrgName: '', //当前ERP单位名称
        currentNodekey: "", //默认选中的节点树
        currentRemark: '', //当前备注
        expandedkeys: [], //默认展开的节点树
        treeExpandedKey: [],
        treeForm: { //组织树新增表单,
          orgName: '',
          orgCode: '',
          remark: '',
          systemDef: ''
        },
        defaultProps: { //组织树默认配置
          label: 'orgName',
          isLeaf: 'isLeaf'
        },
        treeKey: 0,
        searchTreeData: [], //搜索返回的树形数据
        orgNameSearch: '', //根据组织名称模糊搜索
        editButtonShow: true, //编辑按钮显示
        initTree:false,//初始化树的加载
      }
    },
    methods: {
      transformDate(canlinderDate) { //时间转换
        if (canlinderDate) {
          let time = new Date(canlinderDate)
          let lastTime = `${time.getFullYear()}年${time.getMonth()+ 1}月${time.getDate()}日`
          return lastTime
        }
      },
      getsubOrgCat() { //组织类型
        comboBoxDataSelect('c937124a153a4ad2953b690733175f6f').then(res => {
          if (res.data.code == 10000) {
            this.orgTypeData = res.data.data

          }
        })
      },
      getsubOrgDegree() { //组织等级
        comboBoxDataSelect('dfadeac296ca4077a63eea980a80e351').then(res => {
          if (res.data.code == 10000) {
            this.orgTypeDegree = res.data.data
          }
        })
      },
      getCompanyStatus() { //获取企业状态
        comboBoxDataSelect('3a3e807fb3de4652b6c79572f993b903').then(res => {
          if (res.data.code == 10000) {
            this.companyStatus = res.data.data
          }
        })
      },
      getCompanyType() { //获取公司类型
        comboBoxDataSelect('8bbc223e0a444d049d32485e83c19580').then(res => {
          if (res.data.code == 10000) {
            this.companyType = res.data.data
          }
        })
      },
      getZone() { //获取国别或地区
        comboBoxDataSelect('99c3b662fabc46e28a924134fd4a2f28').then(res => {
          if (res.data.code == 10000) {
            this.zoneData = res.data.data
          }
        })
      },
      getBondType() { //获取股票类型
        comboBoxDataSelect('78b4ad0dd6384f0c9ba55ef30671a72c').then(res => {
          if (res.data.code == 10000) {
            this.bondTypeDatas = res.data.data
          }
        })
      },
      getSubOrgCat() { //获取登记注册类型
        comboBoxDataSelect('84da22743c194f7f9f6d3e9f773a4912').then(res => {
          if (res.data.code == 10000) {
            this.subOrgReqCatData = res.data.data
          }
        })
      },
      getSubOrgPlate() { //获取业务板块
        comboBoxDataSelect('494d92fc6f8c41e48e62f7cc11f1ec67').then(res => {
          if (res.data.code == 10000) {
            this.subOrgPlateData = res.data.data
          }
        })
      },
      getRootTree() { //获取树根节点
        treeRoot().then(res => {
          if (res.data.code == 10000) {
            let resDatas = res.data.data
            this.selectTreeId = resDatas[0].treeId
            this.selectTreeOrg = resDatas[0].orgName
            this.rootTreeData = resDatas
            this.initTree = true
          }
        })
      },
      removeTip() { //移除默认提示
        let msgs = document.getElementsByClassName("el-message")
        for (let i = 0, len = msgs.length; i < len; i++) {
          msgs[i].style.display = "none";
        }
      },
      deepChild(val) { //递归遍历树形数据源
        let $this = this;
        if (val && Array.isArray(val) && val.length) {
          val.forEach(item => {
            if (typeof item === 'object') {
              item.orgName = item.name;
              $this.deepChild(item.children);
            }
          })
        }
      },
      changSelectTree(val) { //树下拉切换
        this.rootTreeData.forEach(item => {
          if (item.treeId == this.selectTreeId) {
            this.selectTreeOrg = item.orgName
          }
        })
        this.node.childNodes = []
        this.loadNode(this.node, this.resolve)
      },
      loadNode(node, resolve) { //组织树懒加载
        if (node.level == 0) {
          this.node = node
          this.resolve = resolve
          // if (!this.selectTreeId) {
          //   this.selectTreeId = 1527
          // }
          // if (!this.selectTreeOrg) {
          //   this.selectTreeOrg = 'HR组织'
          // }
          childrenTree(this.selectTreeId).then(res => {
            if (res.data.code == 10000) {
              let data = res.data.data
              data.forEach(item => {
                item.label = item.orgName
                item.id = item.treeId
                item.isLeaf = item.isLeaf == 'n' ? false : true
              })
              if (data.length > 0) {
                this.currentNodekey = data[0].treeId
                this.expandedkeys.push(data[0].treeId)
                this.$nextTick(() => {
                  this.$refs.tree.setCurrentKey(this.currentNodekey)
                })
                this.getAchiveDetails(data[0].orgId)
                this.currentParentTreeId = this.selectTreeId
                this.currentOrgName = this.selectTreeOrg
                this.currentOrgDegree = data[0].orgDegree
                this.currentSortNo = data[0].sortNo
                this.currentErpOrgCode = data[0].erpOrgCode
                this.currentErpOrgName = data[0].erpOrgName
                this.currentRemark = data[0].remark
                this.editButtonShow = true
              } else {
                this.editButtonShow = false
              }
              return resolve(data)
            }
          })
        } else {
          childrenTree(node.data.treeId).then(res => {
            if (res.data.code == 10000) {
              let data = res.data.data
              data.forEach(item => {
                item.label = item.orgName
                item.id = item.treeId
                item.isLeaf = item.isLeaf == 'n' ? false : true
              })
              return resolve(data)
            }
          })
        }
      },
      getAchiveDetails(data) { //获取企业详情
        archiveDetails(data).then(res => {
          if (res.data.code == 10000) {
            if (res.data.data) {
              this.formData = res.data.data
              console.log(this.formData)
              this.formData.orgName = this.currentOrgName
              this.formData.sortNo = this.currentSortNo
              this.formData.erpOrgCode = this.currentErpOrgCode
              this.formData.erpOrgName = this.currentErpOrgName
              this.formData.remark = this.currentRemark
              this.formData.orgDegree = this.currentOrgDegree
              this.formData.fromTime = this.transformDate(this.formData.fromTime)
              this.formData.approvedTime = this.transformDate(this.formData.approvedTime)
              this.formData.toTime = this.transformDate(this.formData.toTime)
              this.formData.cancelDate = this.transformDate(this.formData.cancelDate)
              this.formData.estiblishTime = this.transformDate(this.formData.estiblishTime)
              this.formData.revokeDate = this.transformDate(this.formData.revokeDate)
            }
          }
        })
      },
      handleNodeClick(val, node) { //点击树
        if (node.parent.data) {
          this.currentOrgName = node.parent.data.orgName
        } else {
          this.rootTreeData.forEach(item => {
            if (item.treeId == this.selectTreeId) {
              this.currentOrgName = item.orgName
            }
          })
        }
        if (node.parent.data) {
          this.currentParentTreeId = node.parent.data.treeId
        } else {
          this.currentParentTreeId = this.selectTreeId
        }
        this.currentOrgDegree = val.orgDegree
        this.currentSortNo = val.sortNo
        this.currentErpOrgCode = val.erpOrgCode
        this.currentErpOrgName = val.erpOrgName
        this.currentRemark = val.remark
        this.getAchiveDetails(val.orgId)
      },
      clearTreeAdd() { //清空组织树新增
        this.treeForm = {
          orgName: '',
          orgCode: '',
          remark: '',
          systemDef: ''
        }
      },
      addTree() { //组织树新增
        this.clearTreeAdd()
        this.addDialogTree = true
        if (this.$refs.treeForm != undefined) {
          setTimeout(() => {
            this.$refs.treeForm.resetFields()
          }, 10)
        }
      },
      treeSearch() { //组织树搜索
        this.selectTreeBox = false
        this.$nextTick(() => {
          this.$refs.searchFcus.focus()
        })
      },
      searchBlur() { //树搜索失焦
        this.selectTreeBox = true
        this.orgNameSearch = ''
      },
      treeSave(formName) { //组织树新增保存
        this.$refs[formName].validate((valid) => {
          if (valid) {
            addTree(this.treeForm).then(res => {
              if (res.data.code == 10000) {
                this.treeKey++
                this.addDialogTree = false
                Message({
                  message: '新增成功!',
                  type: 'success'
                })
              }
            })
          }
        })
      },
      jumpRouter(data) { //动态路由跳转
        this.$router.addRoutes(this.multiRouters([{
          path: 'addOrEditorganizationTree',
          name: 'addOrEditorganizationTree', //自定义name名称
          component: () => import('@/views/org/organizationTree/addOrEditorganizationTree'),
          meta: {}
        }]));
        this.$router.push(this.routerMatch({
          name: "addOrEditorganizationTree", //顶部导航+侧边导航
          params: {
            data
          }
        }))
      },
      editTreeOrg() { //编辑
        let data = this.$refs.tree.getCurrentNode()
        data.title = '编辑'
        data.parentOrgName = this.currentOrgName
        data.parentTreeId = this.currentParentTreeId
        data.topTreeId = this.selectTreeId
        this.jumpRouter(data)
      },
      addTreeOrg() { //新增
        if (this.$refs.tree.getCurrentNode()) {
          let data = this.$refs.tree.getCurrentNode()
          data.title = '新增'
          data.parentOrgName = this.currentOrgName
          data.parentTreeId = this.currentParentTreeId
          data.topTreeId = this.selectTreeId
          this.jumpRouter(data)
        } else {
          let data = {}
          data.title = '新增'
          data.parentOrgName = this.currentOrgName
          data.parentTreeId = this.currentParentTreeId
          data.topTreeId = this.selectTreeId
          this.jumpRouter(data)
        }
      },
    }
  }
</script>
<style lang="scss">
  .el-button.el-button-pad {
    padding-left: 8px;
    padding-right: 8px;
  }

  .basic-info {
    font-size: 14px;
    line-height: 32px;
    color: #303133;
    font-weight: 700
  }

  .code-first-row {
    margin-bottom: 6px;
  }

  .line-style {
    width: 2px;
    height: 8px;
    background: #409EFF;
    display: inline-block;
    margin-right: 6px;
    vertical-align: middle;
  }

  .code-first-row {
    margin-bottom: 6px;
  }



  .plus-icon:hover {
    color: #409EFF;
    cursor: pointer;
  }

  .textarea-inner-style {
    .el-form-item__content {
      flex: 1;

    }
  }

  .inner-inputs-style {
    display: flex !important;
  }
</style>
